/**
* 描述：简历管理
*/
<style lang="scss" scoped>
  @import 'src/styles/company/index';
</style>
<template>
  <div class="content">
    <div class="com-main-title">
      <span class="tit">简历管理</span>
      <div class="clear"></div>
    </div>
    <!--搜索条部分-->
    <div class="search-bar">
      <div class="oneImput fl wth160px">
        <el-input v-model="searchData.name" placeholder="名称" size="small"></el-input>
      </div>
      <div class="oneImput fl wth160px" style="margin-left: 10px">
        <el-select v-model="searchData.statusIn" style="height: 32px" clearable size="small" placeholder="职位类型">
          <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </div>
      <div class="oneImput fr">
        <el-button type="primary" class="search-button fl" icon="search" @click="search" size="small">搜索</el-button>
        <div class="clear"></div>
      </div>
      <div class="clear"></div>
    </div>

    <!--table部分-->
    <div class="table-content">
      <el-table
        size="mini"
        :data="list"
        v-loading="loading"
        :element-loading-text="loadingText"
        highlight-current-row
        border
        style="width: 100%">
        <el-table-column
          prop="name"
          label="用户真实姓名"
          align="center"
          show-overflow-tooltip>
        </el-table-column>
        <el-table-column
          prop="sex"
          align="center"
          label="性别">
          <template slot-scope="scope">
            {{ scope.row.sex | sexType }}
          </template>
        </el-table-column>
        <el-table-column
          prop="birth"
          align="center"
          show-overflow-tooltip
          label="生日">
          <template slot-scope="scope">
            {{ scope.row.birth | formatDate }}
          </template>
        </el-table-column>
        <el-table-column
          prop="education"
          align="center"
          show-overflow-tooltip
          label="学历">
          <template slot-scope="scope">
            {{ scope.row.education | education }}
          </template>
        </el-table-column>
        <el-table-column
          prop="workExperience"
          align="center"
          show-overflow-tooltip
          label="工作年限">
          <template slot-scope="scope">
            {{ scope.row.workExperience | userExperience}}
          </template>
        </el-table-column>
        <el-table-column
          prop="status"
          align="center"
          show-overflow-tooltip
          label="状态">
          <template slot-scope="scope">
            {{ scope.row.status | applyStatus}}
          </template>
        </el-table-column>
        <el-table-column
          prop="jobName"
          align="center"
          show-overflow-tooltip
          label="投递职位">
        </el-table-column>
        <el-table-column
          prop="createdAt"
          align="center"
          show-overflow-tooltip
          label="投递时间">
          <template slot-scope="scope">
            {{ scope.row.createdAt | formatDate }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="140px" fixed="right">
          <template slot-scope="scope">
            <a class="cz" @click="queryDetail(scope.row.id)">查看</a>
            <a class="cz" @click="invitation(scope.row.jobId, scope.row.talentId)" v-show="scope.row.status!==4">邀请</a>
            <a class="cz" @click="invite(scope.row.id, 7, '拒绝')" v-show="scope.row.status!==7">拒绝</a>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <hy-page v-show="pageShow"
               :current-page="searchData.page"
               :page-size="searchData.limit"
               :total-element="totalElement"
               @current-change="currentChange"></hy-page>
    </div>
  </div>
</template>
<script>
  import list from '@/js/mixins/list';
  import { queryList, queryCount, changeStatus } from '@/service/company/resume/resumeMService';
  import { invite } from '@/service/company/jobInvitation/jobInvitationMService';
  import hyHandler from '@/components/handler/handler';
  export default {
    mixins: [list],
    components: {
      hyHandler
    },
    data () {
      return {
        loading: true,
        searchData: {},
        infoShow: false,
        typeList: [
          {value: 1, label: '已发出申请'},
          {value: 2, label: '已查阅'}
        ]
      };
    },
    methods: {
      async _getList () {
        try {
          this.loading = true;
          let result = await queryList(this.searchData);
          let temp = await queryCount(this.searchData);
          if (!result.data.length) result.data = null;
          this.list = result.data || [];
          this.totalElement = temp.data || 0;
          this.loading = false;
        } catch (e) {
          this.loading = false;
        }
      },
      // 邀请
      async invitation (jobId, talentId) {
        this.$confirm(`确定邀请？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          let params = {
            jobId: jobId,
            talentId: talentId
          };
          await invite(params);
          this.$Notice.success({title: `已邀请`});
          this.currentChange();
        }).catch(() => {
        });
      },
      // 加入候选
      invite (id, state, text) {
        this.$confirm(`是否${text}？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          await changeStatus({id: id}, {status: state});
          this.$Notice.success({title: `已${text}`});
          this.currentChange();
        }).catch(() => {
          // this.$Notice.error({title: `操作失败，${text}失败！`});
        });
      },
      // 点击查看预览
      async queryDetail (id) {
        this.$router.push({path: '/company/main/talentPool/detail', query: {id: id}});
      },
      async downModel () {
        window.location.href = `/api/comp/appl/${this.detailData.id}/attachment`;
      }
    }
  };
</script>
